package com.yoo.module_base.utils

import android.content.Context
import android.graphics.drawable.Drawable
import android.widget.TextView
import androidx.core.content.ContextCompat
import java.text.SimpleDateFormat
import java.util.Date

/**
 * date工具类
 */
object DateUtil {
    fun getDateString(dateString: String?, pattern: String?): String {
        var df: SimpleDateFormat? = null
        var date: Date? = null
        try {
            df = SimpleDateFormat(pattern)
            date = df.parse(dateString)
        } catch (e: Exception) {
        }
        return df!!.format(date)
    }

    fun setStartSign(birthday: String, activity: Context?, txtProfileInfoXz: TextView) {
        val context = activity ?: return
        birthday.apply {
            val month = Integer.parseInt(getDateString(birthday, "MM"))
            val day = Integer.parseInt(getDateString(birthday, "dd"))
            var drawable: Drawable? = null
            if (month == 1 && day >= 20 || month == 2 && day <= 18) {
                txtProfileInfoXz.text =
                    context.resources.getString(com.yoo.module_res.R.string.txt_xz_1)
                drawable =
                    ContextCompat.getDrawable(context, com.yoo.module_res.R.mipmap.icon_xz_aquarius)
            } else if (month == 2 && day >= 19 || month == 3 && day <= 20) {
                txtProfileInfoXz.text =
                    context.resources.getString(com.yoo.module_res.R.string.txt_xz_2)

                drawable =
                    ContextCompat.getDrawable(context, com.yoo.module_res.R.mipmap.icon_xz_pisces)
            } else if (month == 3 && day >= 21 || month == 4 && day <= 19) {
                txtProfileInfoXz.text =
                    context.resources.getString(com.yoo.module_res.R.string.txt_xz_3)

                drawable =
                    ContextCompat.getDrawable(context, com.yoo.module_res.R.mipmap.icon_xz_aries)
            } else if (month == 4 && day >= 20 || month == 5 && day <= 20) {
                txtProfileInfoXz.text =
                    context.resources.getString(com.yoo.module_res.R.string.txt_xz_4)

                drawable =
                    ContextCompat.getDrawable(context, com.yoo.module_res.R.mipmap.icon_xz_taurus)
            } else if (month == 5 && day >= 21 || month == 6 && day <= 21) {
                txtProfileInfoXz.text =
                    context.resources.getString(com.yoo.module_res.R.string.txt_xz_5)

                drawable =
                    ContextCompat.getDrawable(context, com.yoo.module_res.R.mipmap.icon_xz_gemini)
            } else if (month == 6 && day >= 22 || month == 7 && day <= 22) {
                txtProfileInfoXz.text =
                    context.resources.getString(com.yoo.module_res.R.string.txt_xz_6)

                drawable =
                    ContextCompat.getDrawable(context, com.yoo.module_res.R.mipmap.icon_xz_cancer)
            } else if (month == 7 && day >= 23 || month == 8 && day <= 22) {
                txtProfileInfoXz.text =
                    context.resources.getString(com.yoo.module_res.R.string.txt_xz_7)

                drawable =
                    ContextCompat.getDrawable(context, com.yoo.module_res.R.mipmap.icon_xz_leo)
            } else if (month == 8 && day >= 23 || month == 9 && day <= 22) {
                txtProfileInfoXz.text =
                    context.resources.getString(com.yoo.module_res.R.string.txt_xz_8)

                drawable =
                    ContextCompat.getDrawable(context, com.yoo.module_res.R.mipmap.icon_xz_virgo)
            } else if (month == 9 && day >= 23 || month == 10 && day <= 22) {
                txtProfileInfoXz.text =
                    context.resources.getString(com.yoo.module_res.R.string.txt_xz_9)

                drawable =
                    ContextCompat.getDrawable(context, com.yoo.module_res.R.mipmap.icon_xz_libra)
            } else if (month == 10 && day >= 23 || month == 11 && day <= 21) {
                txtProfileInfoXz.text =
                    context.resources.getString(com.yoo.module_res.R.string.txt_xz_10)

                drawable =
                    ContextCompat.getDrawable(context, com.yoo.module_res.R.mipmap.icon_xz_scorpio)
            } else if (month == 11 && day >= 22 || month == 12 && day <= 21) {
                txtProfileInfoXz.text =
                    context.resources.getString(com.yoo.module_res.R.string.txt_xz_11)

                drawable = ContextCompat.getDrawable(
                    context,
                    com.yoo.module_res.R.mipmap.icon_xz_sagittarius
                )
            } else if (month == 12 && day >= 22 || month == 1 && day <= 19) {
                txtProfileInfoXz.text =
                    context.resources.getString(com.yoo.module_res.R.string.txt_xz_12)
                drawable = ContextCompat.getDrawable(
                    context,
                    com.yoo.module_res.R.mipmap.icon_xz_capricorn
                )
            }

            val drawableWidth = 15
            val drawableHeight = 15
            drawable!!.setBounds(0, 0, drawableWidth, drawableHeight)
            txtProfileInfoXz.setCompoundDrawablesWithIntrinsicBounds(
                drawable,
                null,
                null,
                null
            )
        }
    }
}